//
// Created by cumt_ on 2022/11/8.
//

#ifndef LOVESTAR_FUNCTIONS_H
#define LOVESTAR_FUNCTIONS_H

#include <QPointF>
#include <QRandomGenerator>

#define IMAGE_ENLARGE 15

// 心形函数
QPointF heart_function(qreal t, qreal shrink_ratio = IMAGE_ENLARGE) {
    qreal x = 16 * (sin(t) * sin(t) * sin(t));
    qreal y = -(13 * cos(t) - 5 * cos(2 * t) - 2 * cos(3 * t) - cos(4 * t));
    x *= shrink_ratio;
    y *= shrink_ratio;
    return QPointF(x, y);
}

// 指数分布, 随机内部扩散点
QPointF scatter_inside(QPointF &point, qreal beta = 0.05) {
    qreal ratiox = -log(QRandomGenerator::global()->bounded(1.0)) * beta;
    qreal ratioy = -log(QRandomGenerator::global()->bounded(1.0)) * beta;
    qreal dx = point.x() * ratiox;
    qreal dy = point.y() * ratioy;
    return QPointF(point.x() - dx, point.y() - dy);
}

QPointF caculate_position(QPointF &point, qreal ratio = 0.9) {
    qreal force = 1 / qPow((point.x() * point.x() + point.y() * point.y()), 0.6);
    qreal dx = point.x() * force * ratio + QRandomGenerator::global()->bounded(-1, 1);
    qreal dy = point.y() * force * ratio + QRandomGenerator::global()->bounded(-1, 1);
    return QPointF(point.x() - dx, point.y() - dy);
}

QPointF shrink_ratio(QPointF &point, qreal ratio = 0.9) {
    qreal force = 1 / qPow((point.x() * point.x() + point.y() * point.y()), 1);
    qreal dx = point.x() * force * ratio;
    qreal dy = point.y() * force * ratio;
    return QPointF(point.x() - dx, point.y() - dy);
}

qreal curve(qreal p) {
    return 2 * (2 * sin(4 * p)) / (2 * M_PI);
}


#endif //LOVESTAR_FUNCTIONS_H
